home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / alignPreset.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  8.4 KB  |  278 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  April 17, 1997
  22. //  Author:        mgr 
  23. //
  24. //  Description:
  25. //      The alignPreset() procedure executes an align curve/surface operation
  26. //      on a pair of curves/surfaces based on the align option vars. In general
  27. //        if you have n curves/surfaces selected, only the last 2 curves/surfaces
  28. //        would be aligned.
  29. //
  30. //  Input Arguments:
  31. //      None.
  32. //
  33. //  Return Value:
  34. //      None.
  35. //
  36.  
  37. proc string pieceTogetherAlignCmd(
  38.      int $history,
  39.     int $replaceOriginal,
  40.      int $attach,
  41.     int $keepMultKnots,
  42.     int $positionalType,
  43.     int $doTangent,
  44.     int $tangentType,
  45.     int $doCurvature,
  46.     float $tangentScale1,
  47.     float $tangentScale2,
  48.     float $curvatureScale1,
  49.     float $curvatureScale2 )
  50. //
  51. //    Description :
  52. //        Piece together an align command.
  53. //
  54. {
  55.     string $cmd = "";
  56. //    $cmd = "align ";
  57.  
  58.     // construction history
  59.     $cmd = $cmd + " -ch ";
  60.     if ( $history == 1 ) $cmd = $cmd + "on";
  61.     else  $cmd = $cmd + "off";
  62.     
  63.     // replace original
  64.     if ( $replaceOriginal == 1 ) $cmd = $cmd + " -rpo on";
  65.     else $cmd = $cmd + " -rpo off";
  66.  
  67.     // attach
  68.     if ( $attach == 1 )
  69.     {
  70.         $cmd = $cmd + " -at true";
  71.         if ( $keepMultKnots == 1 ) $cmd = $cmd + " -kmk true";
  72.         else $cmd = $cmd + " -kmk false";
  73.     }
  74.     else
  75.     {
  76.         // when attach is off, keep multiple knots has no meaning
  77.         $cmd = $cmd + " -at false -kmk false";
  78.     }
  79.  
  80.     // positional continuity type
  81.     $cmd = $cmd + " -pct " + $positionalType;
  82.  
  83.     // tangent continuity
  84.     if ( $doTangent == 1 )
  85.     {
  86.         $cmd = $cmd + " -tc true -tct " + $tangentType + " -ts1 " + $tangentScale1 + " -ts2 " + $tangentScale2;
  87.         if ( $doCurvature == 1 ) $cmd = $cmd + " -cc true -cs1 " + $curvatureScale1 + " -cs2 " + $curvatureScale2;
  88.         else $cmd = $cmd + " -cc false";
  89.     }
  90.     else
  91.     {
  92.         // tangent continuity is off so curvature continuity does not apply
  93.         $cmd = $cmd + " -tc false -cc false";
  94.     }
  95.  
  96.     return $cmd;
  97.  
  98. }
  99.  
  100. global proc alignPreset(
  101.      int $history,
  102.     int $replaceOriginal,
  103.      int $attach,
  104.     int $keepMultKnots,
  105.     int $positionalType,
  106.     int $doTangent,
  107.     int $tangentType,
  108.     int $doCurvature,
  109.     float $tangentScale1,
  110.     float $tangentScale2,
  111.     float $curvatureScale1,
  112.     float $curvatureScale2 )
  113. //
  114. //    align with the preset options.
  115. //    Use this proc when operation dragged to Shelf.
  116. //
  117. {
  118.     string $cmd = pieceTogetherAlignCmd( $history, $replaceOriginal, $attach, $keepMultKnots, $positionalType, $doTangent, $tangentType, $doCurvature, $tangentScale1, $tangentScale2, $curvatureScale1, $curvatureScale2 );
  119.  
  120.     int $nitems = 2;
  121.     $cmd = appendToCmdPlaceHoldersForSelectionItems( $cmd, $nitems );
  122.  
  123.     // Get the list of nurbs curves/surfaces selected.
  124.     //
  125.     global int $gSelectNurbsCurvesBit;
  126.     global int $gSelectCurvesOnSurfacesBit;
  127.     global int $gSelectNurbsSurfacesBit;
  128.     global int $gSelectIsoparmsBit;
  129.     global int $gSelectCurveParmPointsBit;
  130.     global int $gSelectEditPointsBit;
  131.     string $surfacesList[] = `filterExpand -ex true -sm $gSelectNurbsSurfacesBit -sm $gSelectIsoparmsBit`;
  132.     string $curvesList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit -sm $gSelectCurvesOnSurfacesBit -sm $gSelectCurveParmPointsBit -sm $gSelectEditPointsBit`;
  133.  
  134.     int $numSurfaces = size($surfacesList);
  135.     int $numCurves = size($curvesList);
  136.     if ( $numSurfaces + $numCurves == 0 )
  137.     {
  138.         error("No curves or surfaces selected to align. You must select pairs of curves or surfaces.");
  139.     }
  140.     else if ( $numCurves == 1 && $numSurfaces == 0 )
  141.     {
  142.         error("Not enough curves selected to align. " +
  143.               "You must select pairs of NURBS curves, " +
  144.               "curves on surface, " +
  145.               "points on curves or curve edit points.");
  146.     }
  147.     else if ( $numCurves == 0 && $numSurfaces == 1 )
  148.     {
  149.         error("Not enough surfaces selected to align. " +
  150.               "You must select pairs of NURBS surfaces " +
  151.               "or surface isoparms.");
  152.     }
  153.     else if ( $numCurves == 1 && $numSurfaces == 1 )
  154.     {
  155.         error("Cannot align a NURBS curve to a NURBS surface. " +
  156.               "You must select objects of the same type.");
  157.     }
  158.     else if ( $numCurves > 1 || $numSurfaces > 1 )
  159.     {
  160.         int $doCurveAlign;
  161.         if ( $numCurves > 1 && $numSurfaces > 1 )
  162.         {
  163.              warning("Only 2 objects of the same type should " +
  164.                      "be selected to align. The last selected " +
  165.                      "object will be used to determine which objects to use.");
  166.             // figure out which items were selected last and do align on
  167.             // those types of objects only
  168.             string $selectedList[] = `filterExpand -ex true -sm $gSelectNurbsSurfacesBit -sm $gSelectIsoparmsBit -sm $gSelectNurbsCurvesBit -sm $gSelectCurvesOnSurfacesBit -sm $gSelectCurveParmPointsBit`;
  169.             int $numSelected = size($selectedList);
  170.  
  171.             // if the last selected item is the last surface item then do
  172.             // align on surfaces otherwise do align on curves
  173.             if ( $surfacesList[$numSurfaces-1] == $selectedList[$numSelected-1] ) $doCurveAlign = 0;
  174.             else $doCurveAlign = 1;
  175.         }
  176.         else if ( $numCurves > 1 ) $doCurveAlign = 1;
  177.         else $doCurveAlign = 0;
  178.  
  179.         // just use the last 2 selected curves
  180.         //
  181.         if ( $doCurveAlign == 1 && $numCurves > 2 )
  182.              warning("Only 2 curves should be selected to align. " +
  183.                      "The last 2 selected curves will be used.");
  184.         else if ( $doCurveAlign == 0 && $numSurfaces > 2 ) 
  185.             warning("Only 2 surfaces should be selected to align. " +
  186.                     "The last 2 selected surfaces will be used.");
  187.  
  188.         string $alignPair[2];
  189.         if ( $doCurveAlign == 1 ) 
  190.         {
  191.             $cmd = "alignCurve " + $cmd;
  192.             $alignPair[0] = $curvesList[$numCurves-2];
  193.             $alignPair[1] = $curvesList[$numCurves-1];
  194.         }
  195.         else 
  196.         {
  197.             $cmd = "alignSurface " + $cmd;
  198.             $alignPair[0] = $surfacesList[$numSurfaces-2];
  199.             $alignPair[1] = $surfacesList[$numSurfaces-1];
  200.         }
  201.  
  202.         if ( $history == 0 && $replaceOriginal == 1 && $attach == 1 )
  203.         {
  204.             // delete history on each input to align cmd (so that command won't
  205.             // force history on)
  206.             //
  207.             string $buffer[];
  208.             tokenize($alignPair[0], ".", $buffer);
  209.             string $itemName = $buffer[0];
  210.             $buffer = `listHistory -pdo 1 $itemName`;
  211.             if ( size($buffer) > 0 )
  212.             {
  213.                 // the first item has history so delete it
  214.                 //
  215.                 warning("History will be deleted on first item for align.");
  216.                 evalEcho("delete -ch " + $itemName);
  217.             }
  218.  
  219.             tokenize($alignPair[1], ".", $buffer);
  220.             $itemName = $buffer[0];
  221.             $buffer = `listHistory -pdo 1 $itemName`;
  222.             if ( size($buffer) > 0 )
  223.             {
  224.                 // the second item has history so delete it
  225.                 //
  226.                 warning("History will be deleted on second item for align.");
  227.                 evalEcho("delete -ch " + $itemName);
  228.             }
  229.         }
  230.  
  231.         string $results[] = executeCmdOnItems( $cmd, $alignPair );    
  232.  
  233.         // select the results.
  234.         //
  235.         int $resultCount = size($results);
  236.         if ( $resultCount > 0 ) 
  237.         {
  238.             string $selectString;
  239.             $selectString = "select ";
  240.             if ( $replaceOriginal && $attach )
  241.             {
  242.                 if ( $history == 0 )
  243.                 {
  244.                     // delete the second curve since it is no longer required
  245.                     evalEcho("delete " + $results[1]);
  246.                 }
  247.                 else
  248.                 {
  249.                     // make the second curve an intermediate object (so that
  250.                     // the user won't ever see it). Note: can't do "delete"
  251.                     // here or else align result will go away due to history
  252.                     // on.
  253.                     //
  254.                     string $resultShapes[] = `listRelatives -s $results[1]`;
  255.                     int $shapeCount = size($resultShapes);
  256.                     if ( $shapeCount > 0 )
  257.                     {
  258.                         evalEcho("setAttr " + $resultShapes[0] + ".io true");
  259.                     }
  260.                 }
  261.                 $selectString +=  $results[0];
  262.             }
  263.             else
  264.             {
  265.                 int $i;
  266.                 for ( $i = 0; $i < $resultCount; $i++ ) 
  267.                 {
  268.                     $selectString +=  $results[$i];
  269.                     $selectString += " ";
  270.                 }
  271.             }
  272.             $selectString += ";";
  273.             select -cl;
  274.             eval($selectString);
  275.         }
  276.     }
  277. }
  278.